<?php
namespace frontend\widgets;

use frontend\models\Event;
use yii\bootstrap\Widget;
use yii\behaviors\CacheableWidgetBehavior;

class MainEventsForMainPage extends Widget
{
    private $mainEvents;

    public function behaviors()
    {
        return [
            [
                'class' => CacheableWidgetBehavior::className(),
                'cacheDuration' => 3600,
            ],
        ];
    }
    
    public function init()
    {
        parent::init();

        $this->mainEvents = Event::find()
            ->where('event.is_main_event=1')
            ->andWhere(['>=', 'date_start', date('Y-m-d')])
            ->orderBy('date_start')
            ->asArray()
            ->all();
    }

    public function run()
    {   
     
        if(count($this->mainEvents) != 0)
        {
            echo '<div class="container main-events-main-page-container">';
            foreach($this->mainEvents as $event)
            {
                echo '<div class="event-main-item clearfix">
                            <div class="col-md-4 event-main-item__title">
                                <h2>' . $event['title'] . '</h2>
                            </div>
                            <div class="col-md-8 event-main-item__content">
                                ' . $event['content'] . '
                            </div>
                    </div>';
            }
            echo '</div>';
        }  
        
    }


}
